#!/usr/bin/env python
# _*_ coding: utf-8 _*_
# @Time : 2023/1/27 10:53
# @Author : caoshi
# @Version：V1.0
# @File : LongestCommonPrefix.py
# @desc : 14. 最长公共前缀
#           https://leetcode.cn/problems/longest-common-prefix/


def longest_common_prefix(strs):
    ans = strs[0]

    for i in range(1, len(strs)):
        j = 0
        while j < len(strs[i]) and j < len(ans):
            if ans[j] != strs[i][j]:
                break
            j += 1
        ans = strs[i][0: j]
    return ans


result = longest_common_prefix(["flower", "flow", "floiwght"])
print('>>>>>>> ', result)
